<template>
  <div class="category">
   <div class="titles"><p>栏目管理</p></div>
    <!-- 按钮 -->
        <div class="btns">
      <el-button size="big" type="primary" plain @click="toAdd">添 加</el-button>

    </div>
    <!-- 表格 -->
    <el-table :data="list" style="width: 100%" size="small">
      <el-table-column prop="id" label="ID" width="50"> </el-table-column>
      <el-table-column prop="name" label="栏目名称" width="150"> </el-table-column>
      <el-table-column prop="introduce" label="栏目介绍"> </el-table-column>
       <el-table-column prop="nu" label="播出档期" > </el-table-column>
        <el-table-column prop="parentId" label="编号"> </el-table-column>
      <el-table-column label="操作" width="150" align="center"> 
        <template v-slot="scope">
          <el-button size="small" type="danger" @click="del(scope.row)">删除</el-button>
          <el-button size="small" type="primary" @click="edit(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 模态框 -->
    <el-dialog
      class="customer_modal"
      title="添加新栏目"
      :visible.sync="dialogVisible"
      width="60%">
      {{form}}
      <el-form :model="form" label-width="50px">
        <el-form-item label="ID" >
          <el-input v-model="form.id"></el-input>
        </el-form-item>
        <el-form-item label="栏目名称" >
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="栏目介绍" >
          <el-input v-model="form.introduce"></el-input>
        </el-form-item>
        <el-form-item label="播出档期" >
          <el-input v-model="form.nu"></el-input>
        </el-form-item>
        <el-form-item label="编号" >
          <el-input v-model="form.parentId"></el-input>
        </el-form-item>
      </el-form>
      
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="save" size="small">确 定</el-button>
      </span>
    </el-dialog>
    
  </div>
</template>

<style scoped>
.titles{
  float: left;
  margin: 0 auto;
  padding-left: 15px;
}

.titles p{
  font-size: 18px;
	color: rgb(59, 101, 240);
}

.category{
  background-color: #2de036;
  border-radius: 10px;
  height: 60px;
}

.btns{
  float: right;
  margin: 8px auto;
  padding-right: 11px;
}

.dialog{
  margin: auto;
  text-align: center;
  overflow: hidden;
  
}
</style>
<script>
// 导入request , 浏览器提供给我们的用于与后台进行交互的工具 api
import {get,post} from '@/utils/request'
export default {
  data (){
    return {
      form:{},
      list:[],
      dialogVisible:false
    }
  },
  created(){
    this.loadData();
  },
     methods: {
        save() {
            let url = "/category/saveOrUpdate";
            post(url, this.form).then((response) => {
                this.dialogVisible = false;
                this.$message({type:"success", message:response.message});
                this.loadData();
                 this.form ={}
            });
        },
        del(row) {
            let url = "/category/deleteById";
            get(url, {id:row.id}).then((response) => {
                this.$message({type:"success", message:response.message});
                this.loadData();
            });
        },
        edit(row) {
            this.form = JSON.parse(JSON.stringify(row));
            this.dialogVisible = true;
        },
        loadData() {
            let url = "/category/findAll";
            get(url).then((response) => {
                this.list = response.data;
            });
        },
        toAdd() {
            this.dialogVisible = true
        }
    }
}
</script>

<style scoped>

</style>
